/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hhf.logger;

import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import org.slf4j.Logger;
import org.slf4j.MDC;

/**
 *I
 * @author François
 */
public class ProfilerInterceptor {

	@Inject
	@LoggerName("PROFILING")
	Logger logger;

	@AroundInvoke
	protected Object executing(InvocationContext ic) throws Exception {
		String dest = MDC.get("dest");
		long t0 = System.currentTimeMillis();
		try {
			return ic.proceed();
		} finally {
			logger.debug("{}.{}() : {} ms.", new Object[]{
						  ic.getTarget().getClass().getName(),
						  ic.getMethod().getName(),
						  (System.currentTimeMillis() - t0)});
			MDC.put("dest", dest);
		}
	}
}
